package com.crm.controller;

import java.io.IOException;
import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.servlet.ModelAndView;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.crm.model.mpojo.Gatherguests;
import com.crm.model.mpojo.Internatwaters;
import com.crm.model.pojo.Customer;
import com.crm.model.pojo.CustomerOperator;
import com.crm.model.pojo.Timeline;
import com.crm.services.BackmoneyplanService;
import com.crm.services.ContactServices;
import com.crm.services.CustomerServices;
import com.crm.services.DictionaryServices;
import com.crm.services.GatherguestService;
import com.crm.services.OperatorServices;
import com.crm.services.OrderInfoServers;
import com.crm.services.ReturnMoneyService;
import com.crm.services.TimeLineServices;
import com.crm.services.UserServices;
import com.github.pagehelper.PageInfo;

@Controller
@RequestMapping("customer")
public class CustomerController {
	@Autowired
	private CustomerServices cs;//客户服务类
	@Autowired
	private DictionaryServices ds;//字典服务类
	@Autowired
	private OperatorServices os;//操作日志服务类
	@Autowired
	private UserServices us;//用户服务类
	@Autowired
	private TimeLineServices ts;//时间线服务类
	@Autowired
	private ContactServices cons;//联系人服务类
	@Autowired 
	private BackmoneyplanService bps;//计划回款服务类
	@Autowired
	private ReturnMoneyService rms;//回款服务类
	@Autowired
	private GatherguestService gas;//集客服务类
	@Autowired
	private OrderInfoServers ois;//订单服务类
	
	@RequestMapping("/customerInfo2")
	public void customerInfo2() {
		System.out.println("get全部客户");
	}
	
	@RequestMapping("/customerMerger")
	public void customerMerger() {
		System.out.println("get客户合并");
	}
	
	@RequestMapping("/timeline")
	public void timeline() {
		System.out.println("get客户时间线");
	}
	
	//客户导入
//	@GetMapping("/importcustomer")
//	public void importcustomer() {
//		System.out.println("客户导入");
//		//System.out.println("客户信息："+customers);
//	}
	
	//导入
	@PostMapping("importcustomer")
	@ResponseBody
	public int importClient(HttpServletRequest request, HttpServletResponse response) throws IOException{
		System.out.println("公海导入客户");
		MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
		MultipartFile file = multipartRequest.getFile("importcustomer");
		Workbook workbook = null;
		String originalFilename = file.getOriginalFilename();
		String suffix = originalFilename.substring(originalFilename.lastIndexOf(".") + 1);
		if (file.isEmpty()) {
			System.out.println("文件不存在！");
		}else {
			if ("xls".equals(suffix)) {
				System.out.println("文件为xls文件");
				 workbook= new HSSFWorkbook(file.getInputStream());
			}else if ("xlsx".equals(suffix)) {
				System.out.println("文件为xlsx文件");
					 workbook = new XSSFWorkbook(file.getInputStream());
			}else {
				System.out.println("选择文件后缀名错误");
			}
		}
		System.out.println("workbook==="+workbook);
		List<Gatherguests> importClient = gas.importClient(workbook);
		System.out.println("获取到了数据吗？？"+importClient);
		int addClient = gas.addClient(importClient);
		System.out.println("是否成功导入客户为1："+addClient);
		return 0;
	}
	
	@RequestMapping("/collector")
	public ModelAndView collector() {
		System.out.println("社交集客");
		ModelAndView mView=new ModelAndView("customer/collector");
		//所有用户者
		List<String> findAllusername = us.findAllusername();
		String jsonString = JSONObject.toJSONString(findAllusername);
		System.out.println("121111---:"+jsonString);
		mView.addObject("jsonString",jsonString);
		return mView;
	}
	
	@PostMapping("/internationPage")
	@ResponseBody	
	public PageInfo<Map<String, String>> internationPage(Integer pageNum, Integer pageSize) {
		System.out.println("公海+++");
		if (pageNum == null)
			pageNum = 1;
		if (pageSize == null)
			pageSize = 5;
		List<Map<String, String>> selectByPager = gas.selectByPager(pageNum, pageSize);
		PageInfo<Map<String, String>> pager = new PageInfo<Map<String, String>>(selectByPager);
		System.out.println(pager);
		return pager;
	}
	
	/**
	 * 公海数据
	 * @param pageNum
	 * @param pageSize
	 * @return
	 */
	@RequestMapping("/internationalWaters")
	public ModelAndView internationalWaters(Integer pageNum, Integer pageSize) {
		ModelAndView mView=new ModelAndView("customer/internationalWaters");
		//所有用户者
		List<String> findAllusername = us.findAllusername();
		String username=JSONObject.toJSONString(findAllusername);
		System.out.println("所有用户姓名-------："+username);
		mView.addObject("username",username);
		//部门名称
		List<Map<String, String>> selectDept = gas.selectDept();
		String deptname=JSONObject.toJSONString(selectDept);
		System.out.println("所有部门名称-------："+deptname);
		mView.addObject("deptname",deptname);
		return mView;
	}
	
	/**
	 * 分页查询客户(权限控制)
	 * @param pageNum
	 * @param pageSize
	 * @return
	 */
	@PostMapping("/customerPage")
	@ResponseBody	
	public PageInfo<Map<String, String>> customerPage(Integer pageNum, Integer pageSize) {
		System.out.println("客户+++");
		if (pageNum == null)
			pageNum = 1;
		if (pageSize == null)
			pageSize = 5;
		List<Map<String, String>> selectAll = cs.selectByPager(pageNum, pageSize);
		PageInfo<Map<String, String>> pager = new PageInfo<Map<String, String>>(selectAll);
		System.out.println(pager);
		return pager;
	}
	
	@PostMapping("/customerPage2")
	@ResponseBody	
	public PageInfo<Map<String, String>> customerPage2(Integer pageNum, Integer pageSize) {
		System.out.println("客户+++");
		if (pageNum == null)
			pageNum = 1;
		if (pageSize == null)
			pageSize = 5;
		List<Map<String, String>> selectAll = cs.selectCustomerAll2(pageNum, pageSize);
		PageInfo<Map<String, String>> pager = new PageInfo<Map<String, String>>(selectAll);
		System.out.println(pager);
		return pager;
	}
	
	/**
	 * 条件查询
	 * @param pageNum
	 * @param pageSize
	 * @param cname
	 * @param ctype
	 * @param csort
	 * @param csource
	 * @return 
	 * @return
	 */
	@RequestMapping("/selectByCondition")
	@ResponseBody
	public PageInfo<Map<String, String>> selectByCondition(Integer pageNum, Integer pageSize,
			@RequestParam(name="value7",required=false) Integer value7) {
		System.out.println("条件查询+++++");
		if (pageNum == null)
			pageNum = 1;
		if (pageSize == null)
			pageSize = 5;
		PageInfo<Map<String, String>> pager = null;//分页
		//JSONObject jsonarray=new JSONObject();//请求多个数据
		if (value7==7878) {
			List<Map<String, String>> selectAllCustomer = cs.selectCustomerAll(pageNum, pageSize, value7);
			//分页
			pager=new PageInfo<Map<String, String>>(selectAllCustomer);
		}else if(value7>1104 && value7<=1109) {
			List<Map<String, String>> selectCustType = cs.selectCustType(pageNum, pageSize, value7);//客户种类
			//分页
			pager=new PageInfo<Map<String, String>>(selectCustType);
		}else if(value7>1110 & value7<=1113) {
			List<Map<String, String>> selectCustSort = cs.selectCustSort(pageNum, pageSize,value7);//客户类型
			//分页
			pager=new PageInfo<Map<String, String>>(selectCustSort);
		}else if(value7>1114 & value7<=1125) {
			List<Map<String, String>> selectCustSource = cs.selectCustSource(pageNum, pageSize,value7);//客户来源
			//分页
			pager=new PageInfo<Map<String, String>>(selectCustSource);
		}
		return pager; 
	}
	
	//集客
	@RequestMapping("/publish")
	public ModelAndView custName() {
		ModelAndView mView=new ModelAndView("customer/publish");
		List<Map<String, String>> selectCustName = cs.selectCustName();
		List<Object> receList=new ArrayList<>();
		String jsonString=JSONObject.toJSONString(selectCustName);
		receList.add(jsonString);
		mView.addObject("list",receList);
		return mView;
	}
	
	/**
	 * 模糊查询客户信息
	 * @param custName
	 * @return
	 */
//	@PostMapping("/customerInfo3")
//	public ModelAndView findByCustNameLike(String custName) {
//		ModelAndView mView=new ModelAndView("customer/customerInfo2");
//		List<Customer> findByCustNameLike = cs.findByCustNameLike(custName);
//		String jsonString = JSONObject.toJSONString(findByCustNameLike);
//		System.out.println("模糊查询客户："+jsonString);
//		mView.addObject("likename",jsonString);
//		return mView;
//	}
	
	//模糊查询客户姓名
	@GetMapping("/custLike")
	@ResponseBody	
	public PageInfo<Map<String, String>> custLike(Integer pageNum, Integer pageSize,
			@RequestParam(name="input5",required=false) String input5) {
		System.out.println("模糊查询客户+++");
		if (pageNum == null)
			pageNum = 1;
		if (pageSize == null)
			pageSize = 5;
		List<Map<String, String>> selectCNameLike = cs.selectCNameLike(pageNum, pageSize, input5);
		PageInfo<Map<String, String>> pager = new PageInfo<Map<String, String>>(selectCNameLike);
		System.out.println("模糊查询客户的信息："+pager);
		return pager;
	}
	
	/**
	 * 分页查询客户（转移/共享）
	 * @param pageNum
	 * @param pageSize
	 * @return
	 */
	@RequestMapping("/customerTransfer")
	public ModelAndView transfer(Integer pageNum, Integer pageSize) {
		if (pageNum == null)
			pageNum = 1;
		if (pageSize == null)
			pageSize = 6;
		ModelAndView mView=new ModelAndView("customer/customerTransfer");
		System.out.println("客户转移/共享+++");
		List<Map<String, String>> selectAll = cs.selectByPager(pageNum, pageSize);
		String jsonString=JSONObject.toJSONString(selectAll);
		
		//查询所有用户姓名
		List<String> findAllusername = us.findAllusername();
		String jsonusername=JSONObject.toJSONString(findAllusername);
		System.out.println("用户姓名："+jsonusername);
		mView.addObject("jsonusername",jsonusername);
		
		PageInfo<Map<String, String>> pager = new PageInfo<Map<String, String>>(selectAll);
		System.out.println(pager);
		String json=JSONObject.toJSONString(pager);
		
		mView.addObject("list",jsonString);
		mView.addObject("page",pager);
		mView.addObject("pagejson",json);
		return mView;
	}
	
	@GetMapping("/send01")
	public void addCustomer() {
		System.out.println("get获客1");
	}
	
	@GetMapping("/newInter")
	public void addInte() {
		System.out.println("get新建公海");
	}
	
	@PostMapping("/newInter")
	@ResponseBody
	public String addInter(@RequestParam(name="iwName",required=false) String iwName,
			@RequestParam(name="iwBack",required=false) Integer iwBack,
			@RequestParam(name="iwHistory",required=false) Integer iwHistory,
			@RequestParam(name="iwLimit",required=false) Integer iwLimit,
			@RequestParam(name="deptid[]",required=false) String[] deptid,
			@RequestParam(name="userid[]",required=false) Integer[] userid) {
		System.out.println("post新建公海");
		System.out.println("这是部门id："+deptid);
		System.out.println("部门id："+deptid[0]+",第二个部门id："+deptid[1]);
		System.out.println("员工id："+userid[0]+",第二个员工id："+userid[1]);
		Internatwaters internatwaters=new Internatwaters(2, iwName, iwLimit, iwBack, iwHistory,null , 2);
		int addInter = gas.addInter(internatwaters);
		return "添加成功！";
	}
	
	/**
	 * 获客模板01添加客户
	 * @param name
	 * @param sex
	 * @param phone
	 * @param email
	 * @return
	 */
	@RequestMapping("/send01")
	@ResponseBody
	public JSONObject addCust(@RequestParam(name="name",required=false) String name,
			@RequestParam(name="sex",required=false) Integer sex,
			@RequestParam(name="phone",required=false) String phone,
			@RequestParam(name="email",required=false) String email,
			@RequestParam(name="client",required=false) Integer client) {
		System.out.println("post获客1");
		Gatherguests gatherguests=new Gatherguests(0, null, client, name, sex, phone, email, new Date(System.currentTimeMillis()), new Date(System.currentTimeMillis()), 1441,1444);
		int addGather = gas.addGather(gatherguests);
		System.out.println("是否添加成功："+addGather);
		JSONObject jsonarray=new JSONObject();//请求多个数据
		/*
		 * if (addGather>0) { String infoString=new
		 * String(name+"\t"+phone+"\t"+"从财神到获客模板获取"); String dateString=new
		 * String(client+"\t"+new Date(System.currentTimeMillis()));
		 * jsonarray.put("infoString", infoString); jsonarray.put("dateString",
		 * dateString); System.out.println("#####:"+infoString+"%%%%%%:"+dateString); }
		 */
		return jsonarray;
	}
	
	@GetMapping("/send02")
	public void addCustomer2() {
		System.out.println("get获客2");
	}
	
	/**
	 * 获客模板02添加客户
	 * @param name
	 * @param sex
	 * @param phone
	 * @param email
	 * @return
	 */
	@PostMapping("/send02")
	@ResponseBody
	public String addCust2(@RequestParam(name="name",required=false) String name,
			@RequestParam(name="sex",required=false) Integer sex,
			@RequestParam(name="phone",required=false) String phone,
			@RequestParam(name="email",required=false) String email,
			@RequestParam(name="client",required=false) Integer client) {
		System.out.println("post获客2");
		System.out.println("post获客2222："+client);
		Gatherguests gatherguests=new Gatherguests(0, null, client, name, sex, phone, email, new Date(System.currentTimeMillis()), new Date(System.currentTimeMillis()), 1441,1444);
		gas.addGather(gatherguests);
		return "添加成功！";
	}
	
	@GetMapping("/receiveVisitors")
	public void addCustomer3() {
		System.out.println("get获客3");
	}
	
	//新增客户
	@PostMapping("/addCustomer")
	@ResponseBody
	public String addCustomer(@RequestParam(name="name",required=false) String name,
			@RequestParam(name="shortname",required=false) String shortname,
			@RequestParam(name="sex",required=false) Integer sex,
			@RequestParam(name="source",required=false) Integer source,
			@RequestParam(name="phone",required=false) String phone,
			@RequestParam(name="email",required=false) String email,
			@RequestParam(name="industry",required=false) Integer industry,
			@RequestParam(name="client",required=false) Integer client,
			@RequestParam(name="remarks",required=false) String remarks) {
		System.out.println("新增客户3");
		Customer customer=new Customer();
		customer.setCustName(name);
		customer.setCustShortname(shortname);
		customer.setCustSex(sex);
		customer.setCustSource(source);
		customer.setCustTel(phone);
		customer.setCustEmail(email);
		customer.setIndustry(industry);
		customer.setSuperiorClient(client);
		customer.setRemarks(remarks);
		customer.setStatus(1206);//启用
		customer.setCustTransfer(1443);//普通
		cs.addCust(customer);
		return "0000";
	}
	
	/**
	 * 客户字典表
	 * @return
	 */
	@RequestMapping("/customerDictInfo")
	@ResponseBody
	public JSONArray customerDictInfo() {
		JSONArray array=new JSONArray();
		array.add(ds.ListTransJSONArray(ds.findByDictParentid(1004)));//性别
		array.add(ds.ListTransJSONArray(ds.findByDictParentid(1104)));//客户种类
		array.add(ds.ListTransJSONArray(ds.findByDictParentid(1110)));//客户类型
		array.add(ds.ListTransJSONArray(ds.findByDictParentid(1114)));//客户来源
		array.add(ds.ListTransJSONArray(ds.findByDictParentid(1126)));//客户阶段
		array.add(ds.ListTransJSONArray(ds.findByDictParentid(1133)));//关系等级
		array.add(ds.ListTransJSONArray(ds.findByDictParentid(1138)));//信用等级
		array.add(ds.ListTransJSONArray(ds.findByDictParentid(1142)));//结账方式
		array.add(ds.ListTransJSONArray(ds.findByDictParentid(1150)));//行业
		return array;
	}
	
	//删除客户
	@RequestMapping("/deleteCustomer")
	public int deleteCustomer(@RequestParam("ID") Integer custid) {
		System.out.println("客户编号"+custid);
		Object deleteCustomer = cs.deleteCustomer(custid);
		return 1;
	}
	
	//根据id查询客户
	@PostMapping("selectOne")
	@ResponseBody
	public String selectOne(@RequestParam("custId") Integer custId) {
		System.out.println("客户id:"+custId);
		Map<String, String> findByCustId = cs.findByCustId(custId);
		String jsonString = JSONObject.toJSONString(findByCustId);
		System.out.println("单条客户信息："+jsonString);
		return jsonString;
	}
	
	//修改客户信息
	@PostMapping("updateCustomer")
	@ResponseBody
	public int updateCustomer(@ModelAttribute("c") Customer c) {
		System.out.println("修改客户："+c);
		Object updateCustomer = cs.updateCustomer(c);
		return 1;
//		Integer updateCustomer = (Integer) cs.updateCustomer(c);
//		return updateCustomer;
	}
	
	//批量转移
	@PostMapping("updateClient02")
	@ResponseBody
	public int updateClient02(@RequestParam("client") Integer client,
			@RequestParam("ID[]") Integer[] ID) {
		System.out.println("批量转移id："+ID[0]+",第二个id："+ID[1]+"所有者："+client);
		for (int i = 0; i < ID.length; i++) {
			System.out.println("id的值："+ID[i]);
			//查询原所有者
			Customer findByCustIdPage = cs.findByCustIdPage(ID[i]);
			Integer superiorClient = findByCustIdPage.getSuperiorClient();
			//单条转移
			cs.updateClient2(client, ID[i]);
			//转换时间类型
			Date date1 = new Date();//获取当前时间
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			String str = sdf.format(date1);//时间存储为字符串
			//添加操作日志
			//operCustomer:是登陆的用户id
			CustomerOperator operator=new CustomerOperator(0,  ID[i], null, "转出", Timestamp.valueOf(str), client, null, superiorClient);
			os.insertOper(operator);
		}
		return 1;
	}
	
	//执行合并操作（直接选择两个客户进行合并）
	@PostMapping("executionMerger")
	@ResponseBody
	public int executionMerger(@RequestParam("ID") Integer ID,
			@RequestParam("ID2") Integer ID2) throws ParseException {
		System.out.println("第一个id："+ID+"----第二个id："+ID2);
		//通过id查找到客户
		Customer c1 = cs.findByCustIdPage(ID);
		Customer c2 = cs.findByCustIdPage(ID2);
		//查询订单未完成的客户
		List<Map<String, String>> selelctCustid = ois.selelctCustid(c1.getCustId());
		if(null == selelctCustid || selelctCustid.size() ==0) {
			if (ID>ID2){ 
				//表示客户1添加时间小于客户2添加时间
				//取出客户的字段（判断主客户信息为空的字段）
				if(c2.getCheckout()==null) {
					c2.setCheckout(c1.getCheckout());
				}
				if (c2.getCreditRating()==null) {
					c2.setCreditRating(c1.getCreditRating());
				}
				if (c2.getCustAddress()==null) {
					c2.setCustAddress(c1.getCustAddress());
				}
				if (c2.getCustArea()==null) {
					c2.setCustArea(c1.getCustArea());
				}
				if (c2.getCustName()==null) {
					c2.setCustName(c1.getCustName());
				}
				if (c2.getCustSex()==null) {
					c2.setCustSex(c1.getCustSex());
				}
				if (c2.getCustShortname()==null) {
					c2.setCustShortname(c1.getCustShortname());
				}
				if (c2.getCustSort()==null) {
					c2.setCustSort(c1.getCustSort());
				}
				if (c2.getCustSource()==null) {
					c2.setCustSource(c1.getCustSource());
				}
				if (c2.getCustStage()==null) {
					c2.setCustStage(c1.getCustSource());
				}
				if (c2.getCustType()==null) {
					c2.setCustType(c1.getCustType());
				}
				if (c2.getFirstSigning()==null) {
					c2.setFirstSigning(c1.getFirstSigning());
				}
				if (c2.getIndustry()==null) {
					c2.setIndustry(c1.getIndustry());
				}
				if (c2.getRelationLevel()==null) {
					c2.setRelationLevel(c1.getRelationLevel());
				}
				if (c2.getRemarks()==null) {
					c2.setRemarks(c1.getRemarks());
				}
				if (c2.getSuperiorClient()==null) {
					c2.setSuperiorClient(c1.getSuperiorClient());
				}
				Object updateCustomer = cs.updateCustomer(c2);
				System.out.println("是否合并成功为1****："+updateCustomer);
				Object deleteCustomer = cs.deleteCustomer(ID);//设置客户1的状态为禁用
				System.out.println("客户逻辑删除是否成功为1****："+deleteCustomer);
				//添加一条客户合并时间线
				Timeline tl=new Timeline(0, c2.getCustId(), "将"+c1.getCustName()+"客户合并到"+c2.getCustName()+"中", "客户合并", new Date(System.currentTimeMillis()));
				int insertTimeLine = ts.insertTimeLine(tl);
				System.out.println("是否插入时间线信息为1****："+insertTimeLine);
				System.out.println("合并成功！");
			}
		}else {
			System.out.println("合并不成功！");
		}
		return 1;
	}
	
	//智能合并
	@PostMapping("intelMerger")
	@ResponseBody
	public int executionMerger02() throws ParseException {
		cs.IntellMerger();
		return 1;
	}
	
	/**
	 * 查询时间线
	 * @return
	 */
	@RequestMapping("addtimeline")
	@ResponseBody
	public JSONObject timeline(@RequestParam(name="custid",required=false) Integer custid) {
		System.out.println("查询单条客户时间线");
		JSONObject jsonarray=new JSONObject();//请求多个数据
		List<Map<String, String>> selectAllLine = ts.selectAllLine(custid);
		jsonarray.put("tl", selectAllLine);
		//根据id查询客户
		Map<String, String> findByCustId = cs.findByCustId(custid);
		jsonarray.put("customer", findByCustId);
		//应收/预收
		Object selectReturnIi = ts.selectReturnIi(custid);//智能回款
		if (selectReturnIi!=null) {
			jsonarray.put("intelligent", selectReturnIi);
		}
		Object selectReturnPlan = ts.selectReturnPlan(custid);//计划回款
		if (selectReturnPlan!=null) {
			jsonarray.put("returnmoney", selectReturnPlan);
		}
		Object selectAdvance = ts.selectAdvance(custid);//预付余额
		if (selectAdvance!=null) {
			jsonarray.put("prepaid", selectAdvance);
		}
		//签约数据
		Object selectOrder = ts.selectOrder(custid);//订单总额
		if (selectOrder!=null) {			
			jsonarray.put("contract", selectOrder);
		}
		Object selectRe = ts.selectRe(custid);//发货总额
		if (selectRe!=null) {
			jsonarray.put("deliver", selectRe);
		}
		Object selectOut = ts.selectOut(custid);//退货总额
		if (selectOut!=null) {			
			jsonarray.put("moneyback", selectOut);
		}
		Object selectReturnIntenat = ts.selectReturnIntenat(custid);//实际回款
		if (selectReturnIntenat!=null) {			
			jsonarray.put("signing", selectReturnIntenat);
		}
		return jsonarray;
	}
	
	/**
	 * 转公海
	 */
	@RequestMapping("/updateSea")
	public void updateSea(@RequestParam("ID") Integer custid) {
		System.out.println("转公海客户编号"+custid);
		int updateSea = cs.updateSea(custid);
		//根据客户id查询单条客户
		Customer selectCustId = cs.selectCustId(custid);	
		//添加一条公海数据
		Gatherguests gatherguests=new Gatherguests(0, custid, selectCustId.getSuperiorClient(), selectCustId.getCustName(), 
				selectCustId.getCustSex(),selectCustId.getCustTel(), selectCustId.getCustEmail(),
				new Date(System.currentTimeMillis()), new Date(System.currentTimeMillis()), 1441,1444);
		gas.addGather(gatherguests);
	}
	
	/**
	 * 转普通
	 */
	@RequestMapping("/updateCust")
	public void updateCust(@RequestParam("gaId") Integer gatherid) {
		System.out.println("转普通集客编号"+gatherid);
		//根据集客id查询单条集客信息
		//Gatherguests selectOne = gas.selectGaid(gatherid);
		Gatherguests selectOne = gas.selectOne(gatherid);
		String jsonString = JSONObject.toJSONString(selectOne);
		System.out.println("没转json："+selectOne);
		System.out.println("转json集客信息："+jsonString);
		//System.out.println("客户id存在的："+selectOne.getCustId());
		//判断custid是否为空
		if (selectOne.getCustId()!=null) {
			System.out.println("客户id存在的："+selectOne.getCustId());
			//根据集客信息中的客户id查询客户信息
			Customer selectCustId = cs.selectCustId(selectOne.getCustId());
			//将客户表公海修改成普通
			int updateTransfer = cs.updateTransfer(selectCustId.getCustId());
			System.out.println("修改有客户id的集客信息为1****："+updateTransfer);
		}else if(selectOne.getCustId()==null){
			System.out.println("客户id不存在的："+selectOne.getCustId());
			//新增数据到客户表中
			Customer customer=new Customer(0, new Timestamp(selectOne.getGaCreate().getTime()), 
					null, null, null, null, selectOne.getGaEmail(),selectOne.getGaName(),
					selectOne.getGaSex(),null, null, null, null, selectOne.getGaTel(),
					null, null, null, null, null, selectOne.getuId(), 1206, 1443);
			cs.addCust(customer);
		}
		//将集客表公海修改成普通
		int updateCust = gas.updateCust(gatherid);
		System.out.println("修改集客为普通是否成功为1****："+updateCust);
	}
	
	//回显公海数据
	@RequestMapping("/selectInter")
	@ResponseBody
	public JSONObject selectInter() {
		List<Internatwaters> selectInternat = gas.selectInternat();
		JSONObject jsonarray=new JSONObject();//请求多个数据
		System.out.println("数据是.....："+selectInternat);
		for (Internatwaters inter: selectInternat) {
			jsonarray.put("name", inter.getIwName());
			jsonarray.put("back", inter.getIwBack());
			jsonarray.put("history", inter.getIwHistory());
			jsonarray.put("limit", inter.getIwLimit());
		}
		return jsonarray;
	}
	
	//修改公海数据
	@PostMapping("/updateGather")
	@ResponseBody
	public int updateGather(@RequestParam(name="gaId",required=false) Integer gaId,
			@RequestParam(name="uid",required=false) Integer uid,
			@RequestParam(name="updatetime",required=false) Date updatetime) {
		System.out.println("修改公海数据");
		System.out.println("客户id："+gaId+"\t客户所有者："+uid+"\t客户更新时间："+updatetime);
//		String format = dateFormat.format(updatetime);
//		System.out.println("转换的时间："+format);
		int updateGather = gas.updateGather(gaId, uid, updatetime);
		System.out.println("是否修改成功为1**："+updateGather);
		return updateGather;
	}
	
	//模糊查询公海客户的所有者
	@GetMapping("/unameLike")
	@ResponseBody	
	public PageInfo<Map<String, String>> unameLike(Integer pageNum, Integer pageSize,
			@RequestParam(name="input5",required=false) String input5) {
		System.out.println("模糊查询公海客户所有者+++");
		if (pageNum == null)
			pageNum = 1;
		if (pageSize == null)
			pageSize = 5;
		List<Map<String, String>> selelctUname = gas.selelctUname(pageNum, pageSize, input5);
		PageInfo<Map<String, String>> pager = new PageInfo<Map<String, String>>(selelctUname);
		System.out.println("模糊查询公海的信息："+pager);
		return pager;
	}
}
